/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.gac.testers;

import org.gac.model.*;
import org.gac.ui.BoxScene;
import org.gac.ui.SceneFactory;
import org.gac.ui.SceneSupport;
import org.gac.ui.StepWidgetBase;
import org.netbeans.api.visual.action.ActionFactory;
import org.netbeans.api.visual.border.BorderFactory;
import org.netbeans.api.visual.widget.Widget;


/**
 *
 * @author Tomek
 */
public class GUITester
{
    private static BoxScene _scene;
    private static Step _rootStep;
    
    public static void main(String[] args)
    {
        _scene = new BoxScene();

        _rootStep = GenerateHugeTree();
        //_rootStep = GenerateSeq();
        SplitStep ss = new SplitStep( "Split");
        ss.AddStep(new ExampleStep("Crossing-over"));
        //ss.AddStep(new ExampleStep("sraka1"));
        (( CompositeStep)_rootStep).AddStep(ss);
        StepWidgetBase swb = new SceneFactory().CreateWidgets(_scene, _rootStep );
        _scene.getMainLayer().addChild(swb);
        
        //setAllBorders( _scene.getMainLayer());
        
        _scene.getActions().addAction(ActionFactory.createZoomAction());
        _scene.getActions().addAction(ActionFactory.createPanAction());

        
        _rootStep.setStepChangeListener(new IStepStateListener( ) {
            
            public void StepStateChanged(Step step)
            {
                regenerateScene( _scene );
            }


        });
        
        SceneSupport.show(_scene.createView());
    }
    private static void regenerateScene(BoxScene scene)
    {
        scene.clear();
        StepWidgetBase swb = new SceneFactory().CreateWidgets(scene, _rootStep );
        _scene.getMainLayer().addChild(swb);
    }
    
    public static CompositeStep GenerateSeq()
    {
        SequenceStep result = new SequenceStep( "Sequence1");
        result.AddStep(new ExampleStep( "Crossing-over"));
        result.AddStep(new ExampleStep( "Mutation"));
        result.AddStep(new ExampleStep( "Crossing-over"));
        result.AddStep(new ExampleStep( "Inversion"));
        result.AddStep(new ExampleStep( "Mutation"));
        result.AddStep(new ExampleStep( "Crossing-over"));
        return result;
    }

    public static CompositeStep GenerateSplit()
    {
        SplitStep result = new SplitStep( "Split1");
        result.AddStep(new ExampleStep( "Crossing-over"));
        result.AddStep(new ExampleStep( "Mutation"));
        result.AddStep(new ExampleStep( "Crossing-over"));
        result.AddStep(new ExampleStep( "Inversion"));
        return result;
    }

    public static CompositeStep GenerateBigTree()
    {
        SequenceStep result = new SequenceStep("Sequence2");

        result.AddStep(GenerateSplit());
        result.AddStep(GenerateSplit());

        result.AddStep(new ExampleStep( "Crossing-over"));

        result.AddStep(new ExampleStep( "Crossing-over"));
        result.AddStep(GenerateSplit());
        result.AddStep(GenerateSplit());
        return result;
    }

    public static CompositeStep GenerateHugeTree()
    {
        SplitStep result = new SplitStep( "Split2");
        result.AddStep(GenerateBigTree());
        result.AddStep(GenerateSeq(  ));

        result.AddStep(GenerateBigTree());
        return result;
    }

    private static void setAllBorders( Widget w )
    {
        for( Widget child:w.getChildren())
        {
            setAllBorders(child);
        }
        w.setBorder(BorderFactory.createLineBorder());
    }
}

